<?php
/**
 * @version		1.0.0
 * @category	Anahita Social Simple Blogs
 * @copyright	Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
 * @link     	http://www.anahitapolis.com
 */

/**
 * Simple Blog Applicaiton Model
 *
 */
class ComSblogsModelApplication extends AnSeApplication
{
	/**
	 * Callback called before an actor profile is rendered
	 * 
	 * @param  KCommandContext $context
	 * @return void
	 */
	public function onProfileDisplay(KCommandContext $context)
	{
		$actor   = $context->actor;
		$actions = $context->actions;
		$gadgets = $context->gadgets;
		
		if ( $actor->getAcl()->allowView('com_sblogs:posts') )
			$gadgets->add(array(
				'id'  			=> 'an-discus-gadget-actor-profile',
				'title' 		=> JText::_('AN-SBLOGS-GADGET-ACTOR-PROFILE'),
				'title_url' 	=> JRoute::_('index.php?option=com_sblogs&view=posts&oid='.$actor->id),
				'url'   		=> JRoute::_('index.php?option=com_sblogs&view=posts&layout=profile&oid='.$actor->id),
				'icon_url'		=> 'media/com_discussions/images/icons/discussions.png'
			));
	}

	/**
	 * Callback called before the dashboard is rendered
	 * 
	 * @param  KCommandContext $context
	 * @return void
	 */	
	public function onDashboardDisplay(KCommandContext $context)
	{
		
	}
	
	/**
	 * Publishes a story for a newly created post
	 *
	 * @param  ComSblogsModelPost $post
	 * @return AnSeStory
	 */
	public function publishNewPostStory($post)
	{
		$story = $this->publishStory('new_post', array(			
			'subject' => $post->author,
			'target'  => $post->owner,
			'object'  => $post,
			'owner'	  => array($post->owner, $post->author)		
		));
		
		AnDomain::getContext()->save();
		
		return $story;
	}
	
	/**
	 * Load Story Template is a called by Social Engine to load the Blog story template
	 * 
	 * @return void
	 */
	protected function _loadStoryTemplates()
	{
		$this->addStoryTemplate(array(
			'name'  		=> 'new_post'
		));
	}	
}